<template>
	<view>
		<u-popup :show="true" mode="center" :round="10">
			<view class="tips">
				<text class="text">小程序需要获取你的信息才能正常使用！</text>
				<u-button plain type="primary" @click="getuserinfo()">确认授权</u-button>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import request from '@/utills/request.js'
	export default {
		data() {
			return {
				userInfo: '',
				hasUserInfo: false
			}
		},
		onLoad() {
			this.tokenCkeck();
		},
		methods: {
			getuserinfo() {
				var that = this;
				wx.getUserProfile({
					desc: '用于完善会员资料',
					success: (res) => {
						console.log("res", res);
						wx.login({
							success: (r) => {
								let code = r.code
								console.log("r",r);
								wx.request({
									url: that.baseurl + 'user/login',
									method: "POST",
									data: {
										jsCode: code,
										nickName: res.userInfo.nickName,
										userAvatarUrl: res.userInfo.avatarUrl,
									},
									success(result) {
										console.log(result);
										uni.setStorageSync("token", result.data.data)
										uni.switchTab({
											url: '../main/main'
										})
									}
								})
							}
						})
					}
				})
			},
			async tokenCkeck() {
				let res = await request({
					method: 'get',
					url: 'user/tokenCheck'
				})
				// console.log(res);
				if (res.data.code == 200) {
					uni.switchTab({
						url: '../main/main'
					})
				} else {
					console.log("tokenCheck", res);
				}
			}
		},
	}
</script>

<style>
	.tips {
		padding: 34.97rpx;
	}

	.text {
		display: block;
		padding-bottom: 20rpx;
	}
</style>
